package com.example.people_big_people.util

import android.util.Log
import java.lang.ref.WeakReference
import kotlin.reflect.KProperty

/**
 * @Author      : 鲁班七号
 * @package_name       : com.example.people_big_people.util
 * @Date        : on 2022-10-13 15:50.
 * @Description :若应用
 */
class Weak<T : Any>(initializer: () -> T?) {
    var weakReference = WeakReference<T?>(initializer())

    constructor() : this({
        null
    })

    operator fun getValue(thisRef: Any?, property: KProperty<*>): T? {
        Log.d("Weak Delegate", "-----------getValue")
        return weakReference.get()
    }

    operator fun setValue(thisRef: Any?, property: KProperty<*>, value: T?) {
        Log.d("Weak Delegate", "-----------setValue")
        weakReference = WeakReference(value)
    }

}
